
<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form ref="filterForm" :model="filterForm" :inline="true" label-position="left" label-width="100px">
        <el-form-item label="关键字" prop="symbol">
          <el-input v-model="filterForm.symbol" clearable placeholder="项目ID/项目标题/项目内容" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
        </el-form-item>
      </el-form>
      <el-button @click="getBrokerCostList">刷新</el-button>
    </div>
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="symbolList"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column label="合约" prop="symbol" sortable="custom" align="center">
        <template slot-scope="{row}">
          <span><el-input v-model="row.symbol" placeholder="金额"></el-input></span>
        </template>
      </el-table-column>
      <el-table-column label="期货" prop="contract" sortable="custom" align="center">
        <template slot-scope="{row}">
          <span><el-input v-model="row.contract" placeholder="金额"></el-input></span>
        </template>
      </el-table-column>
      <el-table-column label="期货[经纪公司]" prop="id" sortable="custom" align="center">
        <template slot-scope="{row}">
          <span><el-input v-model="row.contractBroker" placeholder="金额"></el-input></span>
        </template>
      </el-table-column>
      <el-table-column label="期货[交易所]" prop="id" sortable="custom" align="center">
        <template slot-scope="{row}">
          <span><el-input v-model="row.contractExchange" placeholder="金额"></el-input></span>
        </template>
      </el-table-column>
      <el-table-column label="费用类型" prop="id" sortable="custom" align="center">
        <template slot-scope="{row}">
          <el-switch
            v-model="row.contractStyle" active-text="固定"  inactive-text="浮动"
            active-color="#13ce66"
            inactive-color="#ff4949">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="费用方向" prop="id" sortable="custom" align="center">
        <template slot-scope="{row}">
          <el-switch
            v-model="row.contractDirection"  active-text="双向"  inactive-text="单向"
            active-color="#13ce66"
            inactive-color="#ff4949">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="杠杆" prop="id" sortable="custom" align="center">
        <template slot-scope="{row}">
          <span><el-input v-model="row.contractMargin" placeholder="金额"></el-input></span>
        </template>
      </el-table-column>
      <el-table-column label="期权" prop="id" sortable="custom" align="center">
        <template slot-scope="{row}">
          <span><el-input v-model="row.option" placeholder="金额"></el-input></span>
        </template>
      </el-table-column>
      <el-table-column label="期权[经纪公司]" prop="id" sortable="custom" align="center">
        <template slot-scope="{row}">
          <span><el-input v-model="row.optionBroker" placeholder="金额"></el-input></span>
        </template>
      </el-table-column>
      <el-table-column label="期权[交易所]" prop="id" sortable="custom" align="center">
        <template slot-scope="{row}">
          <span><el-input v-model="row.optionExchange" placeholder="金额"></el-input></span>
        </template>
      </el-table-column>
      <el-table-column label="费用类型" prop="id" sortable="custom" align="center">
        <template slot-scope="{row}">
          <el-switch
            v-model="row.optionStyle"  active-text="固定"  inactive-text="浮动"
            active-color="#13ce66"
            inactive-color="#ff4949">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="费用方向" prop="id" sortable="custom" align="center">
        <template slot-scope="{row}">
          <el-switch
            v-model="row.optionDirection" active-text="双向"  inactive-text="单向"
            active-color="#13ce66"
            inactive-color="#ff4949">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="杠杆" prop="id" sortable="custom" align="center">
        <template slot-scope="{row}">
          <span><el-input v-model="row.optionMargin" placeholder="金额"></el-input></span>
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="100px" fixed="right">
        <template slot-scope="{row}">
          <el-button type="primary" @click="handleCostSubmitButton(row)">
            保存
          </el-button>
          <el-button type="primary" size="danger" @click="handleRomve(row)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="symbolTotal>0" :total="symbolTotal" :page.sync="filterForm.page" :limit.sync="filterForm.size" @pagination="getBrokerCostList" />

  </div>
</template>

<script>
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import {getBrokerCostList,saveBrokerCost} from '@/api/chinactp/broker'



export default {
  name: 'brokerForm',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      socket:"",
      tableKey: 0,
      symbolList: null,
      symbolTotal: 0,
      listLoading: false,
      connected:"loading",
      depositForm:{
        amount:100
      },
      hiddenDepositWrapper:false,
      filterForm: {
        page: 1,
        size: 20,
        symbol: '',
        status: '0'
      }
    }
  },
  created() {
    let brokerID = this.$route.query.brokerID 
    brokerID = parseInt(brokerID)
    this.brokerID = brokerID
    this.filterForm.brokerID = brokerID
    this.getBrokerCostList()
  },
  methods: {
    getBrokerCostList:function(){
      let _this = this;
      getBrokerCostList(_this.filterForm).then((response) => {
        console.log("getList",response)
          if (response.code === 200) {
            _this.symbolList = response.data.list
            let _symbolList = response.data.list
              console.log(_symbolList)
            _this.symbolList.forEach((index,item)=>{
              console.log(index,item)
              /*
              let _optionData = {
                "contractDirection":false,
                "contractStyle":false,
                "optionDirection":false,
                "optionStyle":false
              }
              if(item['contractDirection'] == 2){
                _symbolList[index]['contractDirection'] = true
              }else{
                _symbolList[index]['contractDirection'] = false
              }
              if(item['contractStyle'] == 2){
                _symbolList[index]['contractStyle'] = true
              }else{
                _symbolList[index]['contractStyle'] = false
              }
              if(item['optionDirection'] == 2){
                _symbolList[index]['optionDirection'] = true
              }else{
                _symbolList[index]['optionDirection'] = false
              }
              if(item['optionStyle'] == 2){
                _symbolList[index]['optionStyle'] = true
              }else{
                _symbolList[index]['optionStyle'] = false
              }
              */
            })
            _this.symbolTotal = response.data.total
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    handleCostSubmitButton:function(costData){
      let _this = this;
      costData['brokerID'] = costData['ID']
      if(costData['contractDirection'] === false){
        costData['contractDirection'] = 1
      }else{
        costData['contractDirection'] = 2
      }
      if(costData['contractStyle'] === false){
        costData['contractStyle'] = 1
      }else{
        costData['contractStyle'] = 2
      }
      if(costData['optionDirection'] === false){
        costData['optionDirection'] = 1
      }else{
        costData['optionDirection'] = 2
      }
      if(costData['optionStyle'] === false){
        costData['optionStyle'] = 1
      }else{
        costData['optionStyle'] = 2
      }
      console.log(costData)
      return false
      saveBrokerCost(costData).then((response) => {
        console.log("getList",response)
          if (response.code === 200) {
            _this.getBrokerCostList()
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    onFormCannelButton:function(){
      this.$router.push({ path: 'broker'})
    }
  }
}
</script>
<style>
</style>